package grpcx

import (
	"booksmart/book/pkg/grpcx/registry"
	"booksmart/book/pkg/logger"
	"google.golang.org/grpc"
	"net"
)

type Server struct {
	Server   *grpc.Server
	Addr     string
	Registry registry.ServiceRegistry
	Logger   logger.LoggerV1
}

func (s *Server) Start() {
	l, err := net.Listen("tcp", s.Addr)
	if err != nil {
		panic(err)
	}

	//嵌入服务注册过程
	s.Registry.Register()

	err = s.Server.Serve(l)
	if err != nil {
		panic(err)
	}
	s.Registry.UnRegister()
}
